package com.spelet;

import java.util.ArrayList;
import java.util.HashMap;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.spelet.UIUtils.FadeInTransitionEffect;
import com.spelet.UIUtils.FadeOutTransitionEffect;
import com.spelet.UIUtils.TransitionEffect;
import com.spelet.UIUtils.TransitionScreen;
import com.spelet.screens.Game;
import com.spelet.screens.LevelSelect;
import com.spelet.screens.CustomGame;
import com.spelet.screens.MainMenu;
import com.spelet.screens.MapEditor;
import com.spelet.screens.Screen;



public class Main implements ApplicationListener{
	public static final Integer SCREEN_MAINMENU = 1;
	public static final Integer SCREEN_GAME = 2;
	public static final Integer SCREEN_MAPEDITOR = 3;
	public static final Integer SCREEN_LEVELSELECT = 4;
	public static final Integer SCREEN_LOADFILE = 5;
	public HashMap<Integer, Screen> screenList;
	public Screen activeScreen;
	public boolean initiated;
	public Main (){
	
	}
	public void initiate() {
		GamePreferences.initiate();
		StaticTextures.intiate();
		StaticSprites.initiate();
		StaticVariables.initiate();
		StaticFonts.initiate();
		DisposableObjects.initiate();
		initiated = true;
		screenList = new HashMap<Integer, Screen>();
		//TODO DIS BAD CODEZ
		screenList.put(SCREEN_MAINMENU, new MainMenu(this));
		screenList.put(SCREEN_GAME, new Game(this,Renderer.getInstance()));
		screenList.put(SCREEN_MAPEDITOR, new MapEditor(this));
		screenList.put(SCREEN_LEVELSELECT, new LevelSelect(this));
		screenList.put(SCREEN_LOADFILE, new CustomGame(this));
		activeScreen = screenList.get(SCREEN_MAINMENU);
		activeScreen.enter();
	}
	public void create() {
		initiated = false;
	}

	public Screen getState(int id) {
		return screenList.get(id);
	}

	public void setScreen(int id) {
		ArrayList<TransitionEffect> effects = new ArrayList<TransitionEffect>();

		effects.add(new FadeOutTransitionEffect());
		effects.add(new FadeInTransitionEffect());

		Screen transitionScreen = new TransitionScreen(this, activeScreen, screenList.get(id), effects);

		activeScreen = transitionScreen;
		//activeScreen = screenList.get(id);
		//activeScreen.enter();
	}

	public void dispose() {
		DisposableObjects.dispose();
	}

	public void pause() {
	}

	public void render() {
		GL20 gl = Gdx.graphics.getGL20();
		gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		if (initiated) {
			activeScreen.update();
			activeScreen.render();
		} else {
			initiate();
		}
	}

	public void resize(int arg0, int arg1) {

	}

	public void resume() {

	}
}
